<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
    <style>
        .fade-enter,
        .fade-leave-to {
            opacity: 0;
        }
        .fade-enter-active,
        .fade-leave-active {
            -webkit-transition: opacity 1s;
            -moz-transition: opacity 1s;
            -ms-transition: opacity 1s;
            -o-transition: opacity 1s;
            transition: opacity 1s;
        }
    </style>
</head>
<body>
<div id="root">
    <transition name="fade" mode="out-in">
        <component :is="type"></component>
    </transition>
    <button @click="handleClick">切换</button>
</div>
<script>
    Vue.component('child', {
        template: '<div>child</div>'
    })

    Vue.component('child-one', {
        template: '<div>child-one</div>'
    })

    let vm = new Vue({
        el:"#root",
        data: {
            type: 'child'
        },
        methods: {
            handleClick: function () {
                this.type = this.type === "child" ? "child-one" : "child"
            }
        }
    })
</script>
</body>
</html>